<?php
// 应用公共文件
function setPassword($password, $encode = ""): array
{
    if (empty($encode)) $encode = \think\helper\Str::random(32);
    $password = password_hash($password . $encode, PASSWORD_DEFAULT);
    return ['password' => $password, 'encode' => $encode];
}

function checkPassword($password, $encode, $password_hash): bool
{
    return password_verify($password . $encode, $password_hash);
}

function getAuthorization()
{
    $author = request()->header("authorization");
    if (empty($author)) throw new \Exception("请登录", 7004);
    return json_decode($author, true);
}

function realDomain(): string
{
    $url = request()->domain();
    if (request()->ip() == "127.0.0.1") $url = "https://jz.verjs.cn";
    return $url;
}
